package com.lagou.servlet;

import com.lagou.bean.Student;
import com.lagou.service.StudentSerive;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "UpdateStudentServlet", value = "/UpdateStudentServlet")
public class UpdateStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1.设置响应输出编码，避免中文乱码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        //2.获取请求中的信息
        String id = request.getParameter("update");
        String sid = request.getParameter("sid");
        String sname = request.getParameter("sname");
        String sex = request.getParameter("sex");
        String birthday = request.getParameter("birthday");
        String email = request.getParameter("email");
        String content = request.getParameter("content");
        //3.创建StudentService对象添加学员
        StudentSerive studentSerive = new StudentSerive();
        Student student = new Student(sid, sname, sex, birthday, email, content);
        int i = studentSerive.updateStudent(student, id);
        System.out.println(i);

        if (0!=1){
            response.sendRedirect("main.jsp");
        }else{
            RequestDispatcher requestDispatcher = request.getRequestDispatcher("main.jsp");
            requestDispatcher.forward(request,response);
        }
    }
}
